package com.sfh.sfhshopweb.dto;

import com.sfh.sfhshopweb.dto.AppHttpCodeEnum;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

@Getter
@Setter
public class ResponseResult<T> implements Serializable {

    private int code;
    private String message;
    private T data;

    public ResponseResult() {
        this.code = 200; // 默认为成功状态码
    }

    public ResponseResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> ResponseResult<T> success(T data) {
        return new ResponseResult<>(200, "Success", data);
    }

    public static <T> ResponseResult<T> success(T data, String message) {
        return new ResponseResult<>(200, message, data);
    }

    public static <T> ResponseResult<T> error(int code, String message) {
        return new ResponseResult<>(code, message, null);
    }

    public static <T> ResponseResult<T> error(AppHttpCodeEnum enums) {
        return new ResponseResult<>(enums.getCode(), enums.getErrorMessage(), null);
    }

    // Getters and Setters (if necessary)
}